//config的设置是全局的
layui
    .config({
        base: '/static/', //根目录
    })
    .extend({
        api: 'js/public/api', //全局API
        popup: 'js/plugin/popup', //弹窗插件
        share: 'js/plugin/share', //分享插件
        beat: 'js/plugin/beat', //数字跳动
        expSelect: 'js/plugin/expSelect', //下拉多选控件
        Countdown: 'js/plugin/countdown', //倒计时插件
        editor: 'js/lib/wangEditor/layuiWangEditor', //富文本编辑器
        request: 'js/public/request', //请求
        md5: 'js/lib/md5/md5', //md5加密模块
        cookie: 'js/lib/jquery-cookie/layui-cookie', //cookie
        qrcode: 'js/lib/qrcode/qrcode', //生成二维码插件
        axios: 'js/lib/axios/axios.layui', //axios请求插件
        swiper: 'js/lib/swiper/swiper', //swiper轮播图插件
    });
//所有项目中都有的效果
layui.use(function () {
    const $ = layui.jquery;
    const util = layui.util;
    //要执行的全局JS
    const global = {
        init: function () {
            let _this = this
            this.layuiEvent()   //点击事件监听
            //监听滚动条事件
            $(window).scroll(function (e) {
                let top = $(this).scrollTop();
                _this.showBackTopBtn(top)

            });
        },
        //返回顶部按钮
        showBackTopBtn: function (scrollTop) {
            let backTop = $('.back-top')
            if (scrollTop >= 200) {
                backTop.show()
            } else if (scrollTop < 20) {
                backTop.hide()
            }
            return backTop
        },
        //layui全局事件监听
        layuiEvent: function () {
            util.on('lay-on', {
                //点击返回顶部
                backTop: function () {
                    $('html,body').animate({
                        scrollTop: 0
                    })
                },

            })
        },
    };
    global.init();
});
